package com.donfu.web.controller.wxhouse;

import com.donfu.common.core.controller.BaseController;
import com.donfu.common.core.domain.AjaxResult;
import com.donfu.system.domain.house.HouseAboutModen;
import com.donfu.system.service.house.IHouseAboutModenService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.util.HtmlUtils;

import java.util.List;

/**
 * 前台关于摩登文章查询
 */
@Api(tags = "前台关于摩登")
@RestController
@RequestMapping("/wx/about")
public class WebHouseAboutModenController extends BaseController {

    @Autowired
    private IHouseAboutModenService houseAboutModenService;

    /**
     * 获取摩登文章详情
     * @return
     */
    @ApiOperation("根据类型显示文章")
    @GetMapping("/getAboutModen/{state}")
    public AjaxResult getInfo(@PathVariable("state") Integer state){
        if(state==null){
            state=1;
        }
        String typeName=null;
        HouseAboutModen houseAboutModen=new HouseAboutModen();
        switch (state){
            case 1:
                typeName="长期价值";
                break;
            case 2:
                typeName="中国制造";
                break;
            case 3:
                typeName="十年质保";
                break;
            case 4:
                typeName="关于摩登";
                break;
            case 5:
                typeName="养护知识";
                break;
            default:
                break;
        }
        houseAboutModen.setTypeName(typeName);
        // 根据类别获取相应的文章，只获取一篇
        List<HouseAboutModen> list = houseAboutModenService.selectHouseAboutModenList(houseAboutModen);
        if(list==null || list.size()==0){
            return AjaxResult.success();
        }
        HouseAboutModen houseAboutModenArticle = list.get(0);
        String content = houseAboutModenArticle.getContent();
        if(content!=null && !content.equals("")){
            String s = HtmlUtils.htmlUnescape(content);
            houseAboutModenArticle.setContent(s);
        }
        return AjaxResult.success(houseAboutModenArticle);
    }

    @ApiOperation("轮播图")
    @GetMapping("/list")
    public AjaxResult findAboutModen(){
        List<HouseAboutModen> houseAboutModenList = houseAboutModenService.selectHouseAboutModenList(null);
        return AjaxResult.success(houseAboutModenList);
    }

    @ApiOperation("获取文章详情")
    @GetMapping("/getArticle/{id}")
    public AjaxResult getArticleInfo(@PathVariable("id") Long id){
        HouseAboutModen houseAboutModen = houseAboutModenService.selectHouseAboutModenById(id);
        return AjaxResult.success(houseAboutModen);
    }
}
